<html>
	<head>
		<title>注册</title>
		<link rel="stylesheet" href="css\bootstrap.css">
		<script src="js/jquery-1.11.3.js"></script>
		<script src="js/bootstrap.js"></script>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8">
	</head>
	<body>
		<div style="height:70px"></div>
		<div class="row">
			<div class="col-xs-4"></div>
			<div class="panel panel-default control-panel col-xs-4">
				<div class="panel-heading">
					<span>新用户注册</span>
				</div>
			</div>
			<div class="panel-body">
				 <form class="form-horizontal" method="post">
						<div class="form-group">
							<label for="input1" class="col-xs-3 control-label">帐号：</label>
							<div class="col-xs-9">
								<input type="text" class="form-control" id="input1" placeholder="userName" name="userName">
							</div>
						</div>
						<div class="form-group">
							<label for="input2" class="col-xs-3 control-label">密码：</label>
							<div class="col-xs-9">
								<input type="password" class="form-control" id="input2" placeholder="passWord" name="passWord">
							</div>
						</div>
						<div class="row"><div class="col-xs-9"></div>
							<div class="btn-group">
							<button class="btn btn-primary"><a herf="index">注册</a></button>
							</div>
						</div>
					</form>
			</div>
		</div>
	</body>
</html>
<?php # script 3.1-db_session.inc.php
	$sdbc=NULL;
	function open_session(){
		global $sdbc;
		$sdbc=mysqli_connect('localhost','username','password','test');
		return true;
	}
	function close_session(){
		global $sdbc;
		return mysqli_close($sdbc);
	}
	function read_session($sid){
		global $sdbc;
		$q=sprintf('SELECT data FROM session WHERE id="%s"',mysqli_real_escape_string($sdbc,$sid));
		$r=mysqli_query($sdbc,$q);
		if(mysqli_num_rows($r) == 1){
			list($data)=mysqli_fetch_array($r,MYSQLI_NUM);
			return $data;
		}else{
			return '';
		}
	}
	function write_session($sid,$data){
		global $sdbc;
		$q=sprintf('REPLACE INTO sessions (id,data) VALUES ("%S","%S")',mysqli_real_escape_string($sdba,$sid),mysqli_real_escape_string($sdbc,$data));
		$r=mysqli_query($sdbc,$q);
		return true;
	}
	function destroy_session($sid){
		global $sdbc;
		$q=sprintf('DELETE FROM session WHERE id="%s"',mysqli_real_escape_string($sdbc,$sid));
		$r=mysqli_query($sdbc,$q);
		$_SESSION=array();
		return true;
	}
	function clean_session($expire){
		global $sdbc;
		$q=sprintf('DELETE FROM session WHERE DATE_ADD(last_accessed,INTERVAL %d SECOND) < NOW()',(int) $expire);
		$r=mysqli_query($sdbc,$q);
		return true;
	}
	session_set_save_handler('open_session','close_session','read_session','write_session','destroy_session','clean_session');
	session_start();

?>